# test_data_volume.py
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from config import CHROMA_PERSIST_DIR
from models.file_models.file_model import File  # 根据你的实际路径导入
import chromadb



def check_chroma_stats():
    client = chromadb.PersistentClient(path=CHROMA_PERSIST_DIR)
    collection = client.get_collection(name="file_search")

    total = collection.count()
    print(f"总条目数: {total}")

    # 获取向量维度
    embedding_dim = collection.get()[0]['dimension']
    placeholder = [[0.0] * embedding_dim]

    # 示例：按app_id统计
    where_filter = {"app_id": "56"}
    filtered_count = count_with_filter(collection, where_filter, placeholder)
    print(f"符合条件 {where_filter} 的条目数: {filtered_count}")


def count_with_filter(collection, where_filter, placeholder_embedding):
    result = collection.query(
        query_embeddings=placeholder_embedding,
        where=where_filter,
        n_results=0
    )
    return len(result.get("ids", []))


if __name__ == "__main__":
    # check_database_stats()
    check_chroma_stats()




#分段质量检测

# from blls.file_search_blls.file_search_bll import FileSearchBLL
#
# def test_segmentation(file_path):
#     segments = list(FileSearchBLL.file_stream_segmenter(file_path, max_length=100))
#     print(f"总分段数: {len(segments)}")
#     for idx, seg in enumerate(segments[:5]):
#         print(f"段{idx+1} 长度{len(seg)}:\n{seg[:100]}...")
#
# if __name__ == "__main__":
#     test_segmentation(r"C:\Users\admin\Desktop\xiyouji.txt")


